<?php
class RoleAction extends CommonAction {
	function index(){
		if(session(C('ADMIN_AUTH_KEY'))){
		    $map = array();
			$map['r.user_id'] = session(C('USER_AUTH_KEY'));
	    }else{
			$map['r.user_id'] = session(C('USER_AUTH_KEY'));
		}
		$this->list=$this->dao -> getList(0,0,$map);
		//echo $this->dao -> getLastSql();
		$this->display();
	}
	public function add(){
		$this->s_gid=M('Role')->select();
		parent::add();
	}
	public function edit(){
		$map['id']=array('neq',$this->_get('id'));
		$map['user_id'] = session(C('USER_AUTH_KEY'));
		$this->s_pid=$this->dao->where($map)->select();
		parent::edit();
	}

	public function insert($data = '', $jumpUrl = '') {
		$_POST['user_id'] = session(C('USER_AUTH_KEY'));
		
		$_POST['pid'] = 0;
		
		
		
		
		if($jumpUrl == ''){
			$jumpUrl = (session('jumpUrl')&&session('jumpUrl')!='') ? session('jumpUrl') : U('Admin/' . MODULE_NAME . '/index');
		}
        
        if ($this->dao->create()) {
            $result = $this->dao->add();
            if (false !== $result) {
				if(strtolower(MODULE_NAME) != 'site'){
				  $this->insert_data = $this->dao->where(array('id' => $result))->find();
				  $this->insert_relate();
				}
				 
                $this->success('操作成功', U('Access/index', array('role_id' => $result)));
            } else {
                $this->error($this->dao->getError());
            }
        } else {
            $this->error($this->dao->getError());
        }
    }

}

?>